<?php

namespace app\admin\model\choi;

use think\Model;
use traits\model\SoftDelete;

class TeacherMoneyLog extends Model
{

    use SoftDelete;

    

    // 表名
    protected $table = 'teacher_money_log';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'source_text'
    ];
    

    
    public function getSourceList()
    {
        return ['1' => __('Source 1'), '2' => __('Source 2'), '3' => __('Source 3')];
    }


    public function getSourceTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['source']) ? $data['source'] : '');
        $list = $this->getSourceList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    /**
     * 添加明细
     */
    public static function add($teacher, $money)
    {
        $data = [
            'teacher_id' => $teacher->teacher_id,
            'money' => $money,
            'before_money' => $teacher->money,
            'after_money' => $teacher->money + $money,
            'source_id' => 0,
            'source' => 3
        ];
        return self::create($data);
    }


}
